package com.agy.filemanager.service.impl;

import com.agy.filemanager.entity.DcBaseSinopecOrg;
import com.agy.filemanager.entity.TreeModel;
import com.agy.filemanager.mapper.DcSystemSinopecOrgDao;
import com.agy.filemanager.service.DcSystemSinpecOrgService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 中石化组织机构
 */
@Service
public class DcSystemSinpecOrgServiceImpl implements DcSystemSinpecOrgService {

    @Autowired
    private DcSystemSinopecOrgDao dcSystemSinopecOrgDao;
    /**
     * 查询组织机构树
     * @return
     */
    @Override
    public List<TreeModel> selectTree() {
        return this.dcSystemSinopecOrgDao.selectTree();
    }

    /**
     * 根据父级编码查询
     * @param parentCode
     * @return
     */
    @Override
    public Page selectGrid(int pageNum,int pageSize,String parentCode,String orgname){
        Page page = PageHelper.startPage(pageNum,pageSize);
        //条件查询
        Example example = new Example(DcBaseSinopecOrg.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("parentCode",parentCode);
        if(!orgname.equals("")){
            criteria.andLike("orgname","%"+orgname+"%");
        }
        List<DcBaseSinopecOrg> list = this.dcSystemSinopecOrgDao.selectByExample(example);
        return page;
    }

    /**
     * 根据id查询子节点
     * @param id
     * @return
     */
    @Override
    public List<TreeModel> childTreeNodes(String id) {
        return this.dcSystemSinopecOrgDao.childTreeNodes(id);
    }
}
